<template>
	<view class="">
		<view class="form-container">
			<view class="form-item">
				<view class="label">预约时间<text class="c-ff6">*</text></view>
				<view class="right">
					<picker mode="date" :value="addData.yutime" :start="startDate" :end="endDate" @change="bindDateChange">
							<view :class="{'c-999':!addData.yutime}">{{addData.yutime?addData.yutime:'请选择'}}</view>
					</picker>
				</view>
			</view>
			<view class="form-item">
				<view class="label">地址<text class="c-ff6">*</text></view>
				<view class="right">
					<input type="text" v-model="addData.address" placeholder="请输入"  />
				</view>
			</view>
			<view class="form-item">
				<view class="label">电话<text class="c-ff6">*</text></view>
				<view class="right">
					<input type="text" v-model="addData.phone" placeholder="请输入"  />
				</view>
			</view>
			<view class="form-item">
				<view class="label">姓名<text class="c-ff6">*</text></view>
				<view class="right">
					<input type="text" v-model="addData.name" placeholder="请输入"  />
				</view>
			</view>
			<view class="pdtb-30 bg-fe fz24 c-ff6 tac" @click="addItem">完成</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			const currentDate = this.getDate({
			            format: true
			        })
			return {
				addData: {
					address:'',
					name:'',
					phone:'',
					yutime:'',
					uid:'',
					gwid:'',
					fbid:''
				},
				date:currentDate,
				id:'',
			}
		},
		onLoad(op) {
			console.log(op)
			this.id = op.id
			this.addData.fbid = op.fbid
		},
		mounted() {
	
		},
		methods: {
			bindDateChange(e) {
					this.addData.yutime = e.target.value
			},
			async init() {
				
			},
			async addItem() {
				let res = null
				this.addData.gwid = this.id 
				this.addData.uid = uni.getStorageSync('uid');
				res = await this.$api.addyuy(this.addData)
				uni.redirectTo({
						url:'/pages/appoint/appoint'
				})
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
						year = year - 60;
				} else if (type === 'end') {
						year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			}
		},
		computed: {
				startDate() {
						return this.getDate('start');
				},
				endDate() {
						return this.getDate('end');
				}
		},
	}
</script>

<style>

</style>
